<template>
  <div class="basic-container"
       :style="styleName"
       :class="{'basic-container--block':block}"

  >
    <el-card :style="heightStyle" class="basic-container__card" :shadow="shadow">
      <slot></slot>
    </el-card>
  </div>
</template>

<script>
export default {
  name: "basicContainer",
  props: {
    shadow: {
      type: String,
      // always、hover 或 never
      default: "hover"
    },
    radius: {
      type: [String, Number],
      default: 10
    },
    background: {
      type: String
    },
    height: {
      type: [String, Number],
      default: 'unset'
    },

    block: {
      type: Boolean,
      default: false
    }
  },
  computed: {
    heightStyle() {
      return {height: this.formatHeight(this.height)}
    },
    styleName() {
      return {
        borderRadius: `${this.radius}px`,
        background: this.background,
        height: this.formatHeight(this.height)

      }
    }
  },
  methods: {
    formatHeight(height) {
      if (height === null || height === undefined) {
        return ''
      }
      // 检查是否为 'auto'
      if (height === 'auto') {
        return 'auto';
      }

      // 检查是否为百分比
      if (typeof height === 'string' && height.endsWith('%')) {
        return height;
      }

      // 检查是否为数字
      if (typeof height === 'number') {
        return `${height}px`;
      }

      // 默认情况下返回原样
      return height;
    }
  }
};
</script>

<style lang="scss">
.basic-container {
  padding: 10px 6px;
  box-sizing: border-box;

  &--block {
    height: 100%;

    .basic-container__card {
      height: 100%;
    }
  }

  &__card {
    width: 100%;
  }

  &:first-child {
    padding-top: 0;
  }
}
</style>
